package com.yunhe.common.constant;

import com.yunhe.common.util.StringUtil;

/**
 * @title: MqttConsts
 * @Author Chen Lun
 * @Date: 2021/1/21
 */
public class MqttConsts {
    private static final String SPLIT_STR = "/";

    // 排序方式定义
    public enum TOPIC {
        Collect("data/measurement", "数据上传"),
        Recollect("data/measurement/recollect", "数据补招"),
        OrderCollect("order/recollect", "数据补录"),
        HeartbeatClient("heartbeat/client", "站端心跳消息"),
        HeartbeatServer("heartbeat/server", "服务端心跳消息"),
        RunStrategyClient("runStrategy/client", "站端策略消息"),
        RunStrategyServer("runStrategy/server", "服务端策略消息"),
        DPU_SM("GwOut/SM_", "DPU测量值变化数据上传"),
        DPU_AM("GwOut/AM_", "DPU所有测量值数据上传"),
        DPU_TpFile_Client("GwIn/TpFile", "重置站端通道文件"),
        DPU_PtFile_Client("GwIn/PtFile", "重置站端测点文件"),
        DPU_AoeFile_Client("GwIn/AoeFile", "重置站端AOE文件"),
        DPU_Reset_Client("GwIn/Reset", "DPU重置，无内容"),
        DPU_File_Server("GwOut/FR_", "获取站端网关里的文件");
        private String value;
        private String title;
        TOPIC(String value, String title) {
            this.value = value;
            this.title = title;
        }
        public String value(Long stationCode) {
            String paramStr = stationCode.toString();
            return value + SPLIT_STR + paramStr;
        }
        public String value(String str) {
            return value + SPLIT_STR + str;
        }
        public String value() {
            return value;
        }
        public String title() {
            return title;
        }
        public Long getStationCode(String value) {
            if (!StringUtil.isEmpty(value)) {
                String stationCode = value.substring(value.lastIndexOf("/") + 1, value.length());
                if (!StringUtil.isEmpty(stationCode)) {
                    return Long.parseLong(stationCode);
                }
            }
            return null;
        }
    }
}